<?php
/**
 *	description:ZMAXWECHAT 消息队列模型
 *  author：min.zhang
 *  Email:zhang19min88@163.com
 *	Url:http://www.zmax99.com
 *  copyright:南宁市程序人软件科技有限责任公司保留所有权利
 *  date:2016-05-01
 * @license GNU General Public License version 3, or later
 *  check date:2016-05-26
 *  checker:min.zhang
 */

defined('_JEXEC') or die('Restricted Access');

jimport('joomla.application.component.modellist');
require_once(JPATH_ROOT."/administrator/components/com_zmaxwechat/libs/wechat/sender.php");

class zmaxwechatModelNewsqueues extends JModelList
{	
	public function __construct($config = array())
	{
		if(empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(
			'id', 
			'title',
			'description',
			'tags'
			);
			if (JLanguageAssociations::isEnabled())
			{
				$config['filter_fields'][] = 'association';
			}
		}
		return parent::__construct($config);
	}
	
	 protected function getListQuery()
	 {
		 
		 $db = JFactory::getDBO();
		 $query = $db->getQuery(true);
		 $query->select("newsqueue_id")->from("#__zmaxwechat_news_map");
		 $db->setQuery($query);
		 $ids = $db->loadcolumn();
		 if(is_array($ids) AND $ids)
		 {
			 $ids = implode(",",$ids);
		 }

		$query = $db->getQuery(true);
		$query->select('n.id ,n.extension ,n.create_date,n.ordering,n.top');
		$query->from('#__zmaxwechat_newsqueue AS n');
		if($ids)
		{
			$query->where('n.id NOT IN ('.$ids.')');	
		}
		$query->select('c.title AS title');
		$query->leftJoin("#__content as c ON c.id = n.article_id");

		$orderCol = $this->state->get("list.ordering" ,'id');
		$orderDirn = $this->state->get("list.direction",'desc');
		$query->order($db->escape($orderCol).' '.$db->escape($orderDirn));
		

		
		return $query;
	 }

}